package com.yyx.jupiter.controller;

import com.yyx.jupiter.entity.CommonResponse;
import com.yyx.jupiter.entity.UpdateVideo;
import com.yyx.jupiter.service.recommend.data.ItemProfileService;
import com.yyx.jupiter.service.recommend.recall.RecallManager;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Validated
@RequestMapping("/video_update")
public class VideoUpdateController {

    @Resource
    RecallManager recallManager;

    @Resource
    ItemProfileService itemProfileService;


    @PostMapping(value = "/add")
    public ResponseEntity<CommonResponse<String>> add(@RequestBody UpdateVideo updateVideo) throws Exception {
        // 更新正排
        itemProfileService.updateVideoProfile(updateVideo);
        // 更新新品召回
        recallManager.updateNewVideoRecall(updateVideo);
        // 更新下架列表
        itemProfileService.updateVideoRemoveList(updateVideo.getVideoId());
        return ResponseEntity.ok(CommonResponse.success("操作成功"));
    }

    @PostMapping(value = "/update")
    public ResponseEntity<CommonResponse<String>> update(@RequestBody UpdateVideo updateVideo) throws Exception {
        // 更新正排
        itemProfileService.updateVideoProfile(updateVideo);
        return ResponseEntity.ok(CommonResponse.success("操作成功"));
    }

    @PostMapping(value = "/delete")
    public ResponseEntity<CommonResponse<String>> delete(@RequestBody UpdateVideo updateVideo) throws Exception {
        itemProfileService.addVideoRemoveList(updateVideo.getVideoId());
        return ResponseEntity.ok(CommonResponse.success("操作成功"));
    }
}
